package com.example.traning.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

/**
 * @author lei yu
 * @since 2025/04/21
 */
public class UpdateJdbc {

    public static void main(String[] args) throws Exception {
        // 1,注册驱动：⼿动加载字节码⽂件到 JVM 中
        Class.forName("com.mysql.cj.jdbc.Driver");
        // 2,连接数据库：参数1：url、参数2：用户、参数3：密码
        Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/demo", "admin", "admin.me21");
        // 3,获取执行SQL语句的对象
        Statement statement = conn.createStatement();
        int rows = statement.executeUpdate("update emp set sal = sal+100 where ename = 'SMITH';");
        System.out.println("受影响的行数 = " + rows);
        // 4,释放资源
        statement.close();
        conn.close();
    }
}
